"use strict";
cc._RF.push(module, 'fcc1cEzlsBFKYVh2VUvSIzz', 'login_register_pop');
// scripts/loginPop/login_register_pop.js

"use strict";

/**
 * 登录模块
 * 功能：登录注册界面
 */
cc.Class({
    extends: cc.Component,

    properties: {
        edAccount: cc.EditBox,
        edPassword: cc.EditBox,
        tgTrue: cc.Toggle,
        fbSer: cc.Prefab,
        fbService: cc.Prefab,
        _resultStr: ""
    },

    // use this for initialization
    start: function start() {
        cc.loader.loadRes('/text/register', function (error, result) {
            this._resultStr = error || result;
        }.bind(this));
    },

    onTextChangedPhone: function onTextChangedPhone(text, editbox, customEventData) {
        var txt = text;
        if (Utils.isInt(txt) || txt == "") this.phoneNum = txt;else {
            txt = this.phoneNum;
            editbox.string = txt;
            return;
        }
    },

    onTextChangePwd: function onTextChangePwd(text, editbox, customEventData) {
        var txt = text;
        if (txt == "") {
            this.pwd = txt;
        } else {
            var re = txt.replace(/\s+/g, "");
            editbox.string = re;
            this.pwd = txt;
        }
    },

    onRegister: function onRegister() {
        if (Utils.checkInput(this.edAccount.string, this.edPassword.string, null, null, true)) {
            if (this.tgTrue.isChecked) {
                this.checkTelToServer();
            } else {
                ComponentsUtils.showTips("请同意注册协议！");
            }
        }
    },

    checkTelToServer: function checkTelToServer() {
        var recv = function (ret) {
            ComponentsUtils.unblock();
            if (ret.Code !== 0) {
                cc.error(ret.Msg);
                ComponentsUtils.showTips(ret.Msg);
            } else {
                var ret = {
                    account: this.edAccount.string,
                    password: this.edPassword.string
                };
                window.Notification.emit("onRegisterVerify", ret);
                this.onClose();
            }
        }.bind(this);
        var data = {
            Token: User.getLoginToken(),
            Mobile: this.edAccount.string
        };
        CL.HTTP.sendRequestRet(DEFINE.HTTP_MESSAGE.GETVERIFYMOBILE, data, recv.bind(this), "POST");
        ComponentsUtils.block();
    },

    onService: function onService() {
        var canvas = cc.find("Canvas");
        var fbs = cc.instantiate(this.fbService);
        canvas.addChild(fbs);
    },

    //注册协议
    onServer: function onServer() {
        var canvas = cc.find("Canvas");
        var pbser = cc.instantiate(this.fbSer);
        pbser.getComponent(pbser.name).init('注册协议', this._resultStr);
        canvas.addChild(pbser);
        pbser.active = true;
    },

    onClose: function onClose() {
        this.node.getComponent("Page").backAndRemove();
    }
});

cc._RF.pop();